﻿using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;
using VisionCloud.Domain.Common;
using VisionCloud.Domain.DtoModel.Sys;
using VisionCloud.Domain.Filters;
using VisionCloud.Service.Sys;

namespace VisionCloud.Api.Controllers.Sys
{
    /// <summary>
    /// 菜单控制器
    /// </summary>
    [SystemModuleAttribute("菜单控制器")]
    [ApiAuthorize(PolicyEnum.RequireRolePermission)]
    [ApiVersion("1.0")]
    [Route("api/sys/[controller]/[Action]")]
    [ApiExplorerSettings(GroupName = "菜单控制器")]
    public class MenuController : ApiBaseController
    {
        /// <summary>
        /// 菜单服务
        /// </summary>
        public MenuService MenuService { get; set; }

        #region 菜单

        /// <summary>
        /// 新建菜单
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult> CreateMenu(SysMenuDto model)
        {
            return await TryCatchAsync(MenuService.CreateMenu(model, TokenModel.YunUserGuid));
        }

        /// <summary>
        /// 编辑菜单
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult> EditMenu(SysMenuDto model)
        {
            return await TryCatchAsync(MenuService.UpdateMenu(model, TokenModel.YunUserGuid));
        }

        /// <summary>
        /// 删除菜单
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult> DeleteMenu(SysMenuDto model)
        {
            return await TryCatchAsync(MenuService.DeleteMenu(model.MenuId, TokenModel.YunUserGuid));
        }

        /// <summary>
        /// 获取菜单列表
        /// </summary>
        /// <param name="condition"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult> GetMenuList(SysMenuCondition condition)
        {
            return await TryCatchAsync(MenuService.GetPage(condition));
        }

        #endregion 菜单
    }
}